<template>
    <view> 
        <view class="giftbox-section-title" v-if="showTitle">
            <image :src="titleImage" mode="aspectFit" class="giftbox-title-img" />
        </view>

        <view class="product-container">
            <view v-for="(item, index) in productList" :key="index" class="product-item">
                <image :src="item.goods_image" class="product-image" mode="‌aspectFill" @click="handleProductClick(item)" />
                <view class="product-info">
                    <view class="product-title">{{ item.goods_name }}</view>
                    <view class="price-buy-container">
                        <view class="price-section">
                            <view class="price-stack">
                                <!-- <text class="activity-label">{{ priceLabel }}</text> -->
                                <text class="product-price">
                                    <text style="font-size: 12px">¥</text>
                                    {{ item.online_price }}</text>

                                <view class="temperature-box" v-if="item.rebate > 0">
                                    {{ item.rebate }}<text style="letter-spacing: 2rpx;margin-left: 2rpx;">福气值</text>
                                </view>
                            </view>
                          
                        </view>
                        <view class="buy-button" @click="handleProductClick(item)">
                            <text>{{ buttonText }}</text>
                        </view>
                    </view>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
/**
 * 商品展示组件
 * @description 用于展示商品列表的网格布局组件
 */
export default {
    name: 'ProductGrid',
    props: {
        // 商品列表数据
        productList: {
            type: Array,
            default: () => []
        },
        // 是否显示标题图片
        showTitle: {
            type: Boolean,
            default: true
        },
        // 标题图片地址
        titleImage: {
            type: String,
            default: 'https://safood-1317438654.cos.ap-guangzhou.myqcloud.com/tempImage/173467531767650b7524efa.png'
        },
        // 价格标签文本
        priceLabel: {
            type: String,
            default: '活动价'
        },
        // 按钮文本
        buttonText: {
            type: String,
            default: '点击购买'
        }
    },
    methods: {
        handleProductClick(item) {
            this.$emit('product-click', item);
            uni.navigateTo({
                url: "/pages/mer/goods/details/details?id=" + item.id,
            });
        }
    }
}
</script>

<style lang="scss" scoped>
.temperature-box {
	 background-color: #C39646;
	 border-radius: 16rpx 16rpx 16rpx 16rpx;
	 color: #FFFFFF; 	 	 	 	 	 	/* 白色文字 */
	 font-size: 20rpx; 	 	 	 	 	/* 文字大小 */
	 margin-top: 8rpx;
	 height: 28rpx;
	 text-align: center;
	 padding: 5rpx;
	 line-height: 28rpx;
	 }
.giftbox-section-title {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 120rpx;
    // padding-bottom: 20rpx;
    background-color: #FFF7F0;
}

.giftbox-title-img {
    width: 100%;
    height: 80rpx;
    /* 根据实际图片调整高度 */
}

.product-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 28rpx;
    padding: 32rpx;
    // background-color: #fff;
    background-color: #FFF7F0;
    // padding-bottom: env(safe-area-inset-bottom);
}

.product-item {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    border-radius: 12px;
    overflow: hidden;
    padding: 12px;
    position: relative;
    min-height: 213px;
    background-image: url("https://safood-1317438654.cos.ap-guangzhou.myqcloud.com/tempImage/173379450967579acd8dd34.png");
    background-size: 100% 100%;
    background-position: center;
    background-repeat: no-repeat;
}

.product-item::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
}

.product-image {
    width: 264rpx;
    height: 212rpx;
    border-radius: 8px;
    position: relative;
    z-index: 2;
}

.product-info {
    padding: 8px 0;
    position: relative;
    z-index: 2;
    width: 100%;
}

.product-title {
    font-size: 14px;
    margin-bottom: 18px;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: break-word;
    line-height: 1.3;
    color: #794628;
    width: 100%;
    max-width: 100%;
    min-height: calc(14px * 1.3);
    max-height: calc(14px * 1.3 * 2);
    box-sizing: border-box;
    // padding-right: calc(100% - (14px * 8));
}

.price-buy-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.price-section {
    display: flex;
    align-items: flex-end;
    flex: 1;
    min-width: 0;
}

.price-stack {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.activity-label {
    font-size: 10px;
    color: #e06b6b;
    line-height: 1;
    margin-bottom: 2px;
}

.product-price {
    color: #d13e3e;
    font-size: 28rpx;
    font-weight: bold;
    line-height: 1;
}

//按钮
.buy-button {
    width: 164rpx;
    height: 64rpx;
    background: linear-gradient(148deg, #db5656 0%, #c41f1f 100%);
    border-radius: 16px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    z-index: 10;

    text {
        z-index: 12;
        font-size: 28rpx;
        color: #f9ddb3;
        line-height: 32px;
        text-align: center;
    }

    &::before {
        content: "";
        position: absolute;
        top: -2px;
        left: -2px;
        right: -2px;
        bottom: -2px;
        background: linear-gradient(125deg,
                rgba(224, 184, 121, 1),
                rgba(249, 221, 179, 1),
                rgba(234, 189, 156, 1));
        border-radius: 18px;
        z-index: -1;
    }

    &::after {
        content: "";
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: inherit;
        border-radius: 16px;
        z-index: 0;
    }
}
</style>
